<template>
<div id="p-main">
    <h3 class="photo-title">
        tabId: {{ title }}
        倒计时:{{minute}}:{{second}}
        <!-- <button @click='add'>点击倒计时</button> -->
    </h3>
    <div id="p-contents" class="animate">
        <ul>
            <li v-for="item in 100" :key="item">
                {{item}}
            </li>
            <!-- <li class="more" @click="handleMore">加载更多</li> -->
        </ul>
    </div>
</div>
</template>

<script>
export default {
    name: "follow",
    data() {
        return {
            title: "",
            minutes:30,
            seconds:0
        }
    },
    beforeRouteEnter (to, from, next) {
        if(to.meta.title) {
            next(vm => {
                vm.title = to.meta.title
            })
        }
    },
    mounted() {
        this.add()
    },
    methods:{
        num:function (n) {
            return n<10 ? "0" + n : "" + n
        },
        add:function () {
            var _this = this;
            var time = window.setInterval(function () {
                if (_this.seconds == '00' && _this.minutes != '00') {
                    _this.seconds = 59;
                    _this.minutes -= 1; 
                }else if(_this.minutes == '00' && _this.seconds == '00'){
                    _this.seconds = 0;
                    window.clearInterval(time);
                    alert('完美')
                }else{
                    _this.seconds -= 1 
                }
            },1000);
        }
    },
    watch:{
        second:{
            handler(newVal){
                this.num(newVal)
            }
        },
        minute:{
            handler(newVal){
                this.num(newVal)
            }
        }
    },
    computed:{
        second:function () {
            return this.num(this.seconds)
        },
        minute:function () {
            return this.num(this.minutes)
        }
    }
}
</script>

<style scoped>
#p-main {
    height: 100%;
    display: flex;
    flex-direction: column;
}
#p-contents {
    flex: 1;
    overflow: auto;
    margin-bottom: 0;
    position: relative;
    display: flex;
    flex-direction: column;
}
.photo-title {
    border:1px solid red;
    margin:5px 10px 0;
    text-align:center;
    box-shadow: 0 0 8px #bf79f8;
    border-radius: 5px;
}
#p-contents ul {
    word-wrap: break-word;
    padding: 0 15px;
}
#p-contents ul li {
    min-height: 50px;
    border: 1px solid #fc8282;
    padding: 6px 8px;
    margin: 8px 0;
    border-radius: 10px;
    box-shadow: 0 0 5px #bf79f8;
}
#p-contents .more {
    line-height: 50px;
    text-align: center;
    border: 1px solid #fc8282;
    box-shadow: 0 0 5px #bf79f8;
    font-size: 20px;
    font-weight: bolder;
    color: red;
}
</style>